/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ca.ubc.icapture.genapha.test.tld;

import ca.ubc.icapture.genapha.beans.Login;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

/**
 *
 * @author btripp
 */
public class LoginLogoutTag extends TagSupport {
    
    @Override
    public int doStartTag() throws JspException {
        return (SKIP_BODY);
    }

    @Override
    public int doEndTag() throws JspException {
        try{
            JspWriter out = pageContext.getOut();
            boolean loggedIn = false;
            HttpSession session = pageContext.getSession();
            if (Login.getLoggedIn(session)) {
                out.println("<a href='logout.do'>Logout</a>");
            }else{
                out.println("<a href='login.do'>Login</a>");
                
            }
        }catch( Exception e){
            System.out.println("the LoginLogoutTag tag error");
            e.printStackTrace();
        }
        return (EVAL_PAGE);
       
    }
}
